package com.ruoyi.common.core.domain.entity;

import com.ruoyi.common.core.domain.BaseEntity;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.io.Serial;
import java.util.ArrayList;
import java.util.List;

/**
 * 菜单权限表 sys_menu
 *
 * @author ruoyi
 */
@EqualsAndHashCode(callSuper = true)
@Entity
@DynamicUpdate
@DynamicInsert
@Data
public class SysMenu extends BaseEntity {
	@Serial
	private static final long serialVersionUID = 1L;

	/**
	 * 菜单ID
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "sys_menu_seq")
	@SequenceGenerator(name = "sys_menu_seq", initialValue = 2000)
	private Long menuId;

	/**
	 * 菜单名称
	 */
	@Column(length = 50)
	@NotBlank(message = "菜单名称不能为空")
	@Size(max = 50, message = "菜单名称长度不能超过50个字符")
	private String menuName;

	/**
	 * 父菜单名称
	 */
	private String parentName;

	/**
	 * 父菜单ID
	 */
	@ColumnDefault("0")
	@Column(length = 20)
	private Long parentId;

	/**
	 * 显示顺序
	 */
	@ColumnDefault("0")
	@Column(length = 4)
	@NotNull(message = "显示顺序不能为空")
	private Integer orderNum;

	/**
	 * 路由地址
	 */
	@Size(max = 200, message = "路由地址不能超过200个字符")
	private String path;

	/**
	 * 组件路径
	 */
	@Size(max = 200, message = "组件路径不能超过255个字符")
	private String component;

	/**
	 * 路由参数
	 */
	private String query;

	/**
	 * 是否为外链（0是 1否）
	 */
	@ColumnDefault("'1'")
	@Column(length = 1)
	private String isFrame;

	/**
	 * 是否缓存（0缓存 1不缓存）
	 */
	@ColumnDefault("'0'")
	@Column(length = 1)
	private String isCache;

	/**
	 * 类型（M目录 C菜单 F按钮）
	 */
	@Column(length = 1)
	@ColumnDefault("''")
	@NotBlank(message = "菜单类型不能为空")
	private String menuType;

	/**
	 * 显示状态（0显示 1隐藏）
	 */
	@ColumnDefault("'0'")
	@Column(length = 1)
	private String visible;

	/**
	 * 菜单状态（0正常 1停用）
	 */
	@ColumnDefault("'0'")
	@Column(length = 1)
	private String status;

	/**
	 * 权限字符串
	 */
	@Size(max = 100, message = "权限标识长度不能超过100个字符")
	private String perms;

	/**
	 * 菜单图标
	 */
	@ColumnDefault("'#'")
	private String icon;

	/**
	 * 子菜单
	 */
	@Transient
	private List<SysMenu> children = new ArrayList<>();

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("menuId", getMenuId())
				.append("menuName", getMenuName())
				.append("parentId", getParentId())
				.append("orderNum", getOrderNum())
				.append("path", getPath())
				.append("component", getComponent())
				.append("isFrame", getIsFrame())
				.append("IsCache", getIsCache())
				.append("menuType", getMenuType())
				.append("visible", getVisible())
				.append("status ", getStatus())
				.append("perms", getPerms())
				.append("icon", getIcon())
				.append("createBy", getCreateBy())
				.append("createTime", getCreateTime())
				.append("updateBy", getUpdateBy())
				.append("updateTime", getUpdateTime())
				.append("remark", getRemark())
				.toString();
	}
}
